package com.example.administrator.printoutindemo.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.dds.soap.SoapListener;
import com.dds.soap.SoapParams;
import com.example.administrator.printoutindemo.R;
import com.example.administrator.printoutindemo.adapter.ShenPiAdapter;
import com.example.administrator.printoutindemo.base.BaseFragment;
import com.example.administrator.printoutindemo.bean.DaishenpiListBean;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jess.arms.base.BaseConstants;

import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;

import java.util.ArrayList;
import java.util.List;

public class LingdaoshenpiListFragment extends BaseFragment {
    private View view;
    private TextView tv_biaotou;
    private ListView lv_fklb;
    private ShenPiAdapter mAdapter;
    private List<DaishenpiListBean> mlists;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_spfk, null);
        tv_biaotou = view.findViewById(R.id.tv_biaotou);
        tv_biaotou.setText("待审核列表");

        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        lv_fklb = view.findViewById(R.id.lv_fklb);
        mlists = new ArrayList<>();
        mAdapter = new ShenPiAdapter(getContext(), mlists);
        lv_fklb.setAdapter(mAdapter);
        getUncheckedDeliveryList();

    }

    private void getUncheckedDeliveryList() {


        String methodName = "GetUncheckedDeliveryList";

        SoapParams params = new SoapParams();


        /**
         * 请求
         */
        soapUtil.callEntry(getUrl(), BaseConstants.NAME_SPACE, methodName, params, new SoapListener() {
            @Override
            public void onSuccess(int statusCode, SoapObject object) {

                String result = object.getProperty(methodName + "Result").toString();
                if (result != null && !result.equals("[]") && !result.equals("anyType{}") && !result.equals("Error") && !result.equals("-100")) {
                    List<DaishenpiListBean> inKuBean = new Gson().fromJson(result, new TypeToken<List<DaishenpiListBean>>() {
                    }.getType());
                    mAdapter.addAll(inKuBean);
                } else {

                }

            }

            @Override
            public void onFailure(int statusCode, String content, Throwable error) {
            }

            @Override
            public void onFailure(int statusCode, SoapFault fault) {
            }
        }, getAapiUserName(), getApiPwd());
    }
}
